home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 32 / Amiga Format AFCD32 (Nov 1998, Issue 117).iso / -seriously_amiga- / programming / e / newgui / src / plugins / pl_register.e < prev    next >
Text File  |  1998-08-10  |  10KB  |  329 lines

  1. /* 
  2.  *  Register-Plugin 1.0
  3.  * -===================-
  4.  * 
  5.  * Planned:
  6.  * --------
  7.  *      - Flexible Text-Length (width graphics/textextent-functions...)
  8.  *      - Image-Support (only to see if there is enaugh space to show it in right of the text (right-aligned))
  9.  */
  10.  
  11. OPT     OSVERSION = 37
  12. OPT     MODULE
  13.  
  14. MODULE  'intuition/intuition'
  15. MODULE  'graphics/rastport'
  16. MODULE  'newgui/newgui'
  17. MODULE  'tools/textlen'
  18.  
  19. EXPORT  CONST   REGISTER = PLUGIN
  20.  
  21. EXPORT  ENUM    REG_ABOVE = 0,
  22.                 REG_LEFT
  23.  
  24. EXPORT OBJECT  register        PRIVATE                                  OF plugin
  25.  list                   :PTR TO LONG
  26.  width                  :INT
  27.  height                 :INT
  28.  fh                     :INT
  29.  num                    :INT
  30.  dir                    :INT
  31.  active                 :INT
  32.  text3d                 :INT
  33.  showbar                :INT
  34.  max                    :INT
  35. ENDOBJECT
  36.  
  37. PROC register(registerlist,active=0,text3d=TRUE,direction=REG_ABOVE,showbar=TRUE)       OF register
  38.  DEF    item=0
  39.   self.list := registerlist
  40.    WHILE ListItem(registerlist,item*2)
  41.     item:=item+1
  42.    ENDWHILE
  43.     self.num:=item
  44.      self.dir:=direction
  45.     self.active:=1
  46.    self.text3d:=IF text3d=FALSE THEN 0 ELSE 1
  47.   self.active:=active
  48.  self.showbar:=IF showbar=FALSE THEN 0 ELSE 1
  49. ENDPROC
  50.  
  51. PROC min_size(ta,fh)                                            OF register
  52.  DEF    width=0,
  53.         height=0,
  54.         item=NIL,
  55.         counter,
  56.         buffer=0,
  57.         image=NIL:PTR TO image
  58.   IF self.dir = REG_ABOVE
  59.    height:=fh+6
  60.     FOR counter:=0 TO self.num
  61.      image:=ListItem(self.list,(counter*2)+1)
  62.       item:=ListItem(self.list,counter*2)
  63.        width:=width+textlen(item,ta)+2
  64.      IF (image<>NIL)
  65.       width:=width+image.width+2
  66.       IF (image.height+2>height) THEN height:=image.height+4
  67.      ENDIF
  68.     ENDFOR
  69.    width:=width + (self.num*8)                                  -> 8 = space between the register elements for the box around ect...
  70.   ELSE                                                          -> Find the bigest String and save its length as maxwidth
  71.    FOR counter:=0 TO self.num
  72.     image:=ListItem(self.list,(counter*2)+1)
  73.      item:=ListItem(self.list,counter*2)
  74.       buffer:=textlen(item,ta)+8
  75.        IF (image<>NIL) THEN buffer:=buffer+image.width+4
  76.      IF (buffer>width) THEN width:=buffer
  77.     IF (image<>NIL)
  78.      IF ((image.height+8)>self.max)
  79.       self.max:=image.height+4
  80.      ENDIF
  81.     ENDIF
  82.    ENDFOR
  83.     width:=width + 8
  84.    height:=self.max*counter
  85.   ENDIF
  86.  self.width:=width
  87.  self.height:=height
  88.  self.fh:=fh
  89.  IF self.max=0 THEN self.max:=self.fh+6
  90. ENDPROC width,height
  91.  
  92. PROC will_resize()                                              OF register
  93.  DEF    resizemode=0
  94.   IF self.dir=REG_ABOVE
  95.    resizemode:=RESIZEX
  96.   ELSE
  97.    resizemode:=RESIZEY
  98.   ENDIF
  99. ENDPROC resizemode
  100.  
  101. PROC render(ta,x,y,xs,ys,w:PTR TO window)                       OF register
  102.  DEF    item=0,
  103.         text=NIL,
  104.         width=0,
  105.         height=0,
  106.         rport=NIL,
  107.         pos=0,
  108.         actpos=0,
  109.         image=NIL:PTR TO image
  110.   IF ta=NIL
  111.    x:=self.x
  112.     y:=self.y
  113.      xs:=self.xs
  114.      ys:=self.ys
  115.     w:=self.gh.wnd
  116.    ta:=self.gh.tattr
  117.   ENDIF
  118.   actpos:=x
  119.   rport:=w.rport
  120.    WHILE (text:=ListItem(self.list,item*2))
  121.     image:=ListItem(self.list,(item*2)+1)
  122.      IF (self.dir = REG_ABOVE)
  123.       width:=textlen(text,ta)+8
  124.        width:=IF (xs>self.width) THEN width+((xs-self.width)/self.num) ELSE width
  125.       IF (image<>NIL) THEN width:=width+image.width+2
  126.       IF (item = self.active)
  127. -> active Box
  128.         SetAPen(rport,1)
  129.          pos:=actpos+1
  130.           Move(rport, pos,  y+ys)
  131.            Draw(rport,pos,  y+2)
  132.           Move(rport, pos+1,y+1)
  133.            Draw(rport,pos+1,y+1)
  134.         SetAPen(rport,2)
  135.          pos:=actpos-2
  136.           Move(rport, pos+4,y)
  137.          pos:=pos+width
  138.            Draw(rport,pos-2,y)
  139.           Move(rport, pos-1,y+1)
  140.            Draw(rport,pos-1,y+1)
  141.           Move(rport, pos,  y+2)
  142.            Draw(rport,pos,  y+ys)
  143. -> Print the Text
  144.          SetDrMd(rport,RP_JAM1)
  145.           SetAPen(rport,1)
  146.            Move(rport,pos-width+5, y+ys-((ys-self.fh)/2)+1)
  147.             Text(rport,text,StrLen(text))
  148.  
  149.         IF (self.text3d=1)
  150. -> Change the Frontpen to white and Print the text one pixel upper and 1 pixel right over the "old" text
  151.          SetAPen(rport,2)
  152.           Move(rport,pos-width+6, y+ys-((ys-self.fh)/2))
  153.          Text(rport,text,StrLen(text))
  154.         ENDIF
  155.        IF (image<>NIL) THEN DrawImage(rport,image,pos-image.width-2,((ys-image.height)/2)+y)+1
  156.       ELSE
  157. -> inactive Box
  158.        IF (self.showbar=1)
  159.         SetAPen(rport,2)
  160.          Move(rport, actpos,y+ys)
  161.           Draw(rport,actpos+width,y+ys)
  162.        ENDIF  
  163.         SetAPen(rport,1)
  164.        IF (self.showbar=1)
  165.         Move(rport, actpos,y+ys-1)
  166.          Draw(rport,actpos+width,y+ys-1)
  167.        ENDIF
  168.         pos:=actpos+1
  169.          Move(rport, pos,  y+ys-2)
  170.           Draw(rport,pos,  y+3)
  171.          Move(rport, pos+1,y+2)
  172.           Draw(rport,pos+1,y+2)
  173.        SetAPen(rport,2)
  174.         pos:=actpos-2
  175.          Move(rport, pos+4,y+1)
  176.         pos:=pos+width
  177.           Draw(rport,pos-2,y+1)
  178.          Move(rport, pos-1,y+2)
  179.           Draw(rport,pos-1,y+2)
  180.          Move(rport, pos,  y+3)
  181.           Draw(rport,pos,  y+ys-2)
  182. -> print the Text
  183.          SetDrMd(rport,RP_JAM1)
  184.           SetAPen(rport,1)
  185.            Move(rport,pos-width+4, y+ys-((ys-self.fh)/2)+1)
  186.             Text(rport,text,StrLen(text))
  187.        IF (image<>NIL) THEN DrawImage(rport,image,pos-image.width-2,((ys-image.height)/2)+y+1)
  188.       ENDIF
  189.      ELSE
  190. ->
  191.       width:=IF (self.height<ys) THEN ((ys-self.height)/self.num) ELSE 0
  192.        height:=self.max+4
  193.       IF (item = self.active)
  194.  
  195.        SetAPen(rport,1)
  196.         pos:=((item)*(height))+y+(width*item)
  197.          Move(rport, x+self.width-2,pos+self.max+2)
  198.           Draw(rport,x+3,           pos+self.max+2)
  199.          Move(rport, x+2,pos+self.max+1)
  200.           Draw(rport,x+2,pos+self.max+1)
  201.          Move(rport, x+1,pos+self.max)
  202.           Draw(rport,x+1,pos+2)
  203.        SetAPen(rport,2)
  204.          Move(rport, x+2,pos+1)
  205.           Draw(rport,x+2,pos+1)
  206.          Move(rport, x+3,pos)
  207.           Draw(rport,x+self.width-2,pos)
  208. -> print the Text
  209.          SetDrMd(rport,RP_JAM1)
  210.           SetAPen(rport,1)
  211.            Move(rport,x+4, pos+self.max-((self.max-self.fh)/2)-2)
  212.             Text(rport,text,StrLen(text))
  213.        IF (self.text3d=1)
  214.           SetAPen(rport,2)
  215.            Move(rport,x+5, pos+self.max-((self.max-self.fh)/2)-3)
  216.             Text(rport,text,StrLen(text))
  217.        ENDIF
  218.  
  219.         IF (image<>NIL) THEN DrawImage(rport,image,x+xs-image.width-3,((self.max-image.height)/2)+pos+2)
  220.  
  221.        IF (self.showbar=1)
  222.          Move(rport, x+self.width-2,pos+self.max+4)
  223.           Draw(rport,x+self.width-2,pos+self.max+2+width)
  224.         SetAPen(rport,1)
  225.          Move(rport, x+self.width-3,pos+self.max+4)
  226.           Draw(rport,x+self.width-3,pos+self.max+2+width)
  227.        ENDIF
  228.       ELSE
  229.  
  230.        SetAPen(rport,1)
  231.         pos:=((item)*(height))+y+(width*item)
  232.         width:=IF (self.height<ys) THEN ((ys-self.height)/self.num) ELSE 0
  233.          Move(rport, x+self.width-4,pos+self.max+2)
  234.           Draw(rport,x+3,           pos+self.max+2)
  235.          Move(rport, x+2,pos+self.max+1)
  236.           Draw(rport,x+2,pos+self.max+1)
  237.          Move(rport, x+1,pos+self.max)
  238.           Draw(rport,x+1,pos+2)
  239.        SetAPen(rport,2)
  240.          Move(rport, x+2,pos+1)
  241.           Draw(rport,x+2,pos+1)
  242.          Move(rport, x+3,pos)
  243.           Draw(rport,x+self.width-4,pos)
  244.  
  245.        IF (self.showbar=1)
  246.          Move(rport, x+self.width-2,pos-2)
  247.           Draw(rport,x+self.width-2,pos+self.max+2+width)
  248.         SetAPen(rport,1)
  249.          Move(rport, x+self.width-3,pos-2)
  250.           Draw(rport,x+self.width-3,pos+self.max+2+width)
  251.        ENDIF
  252.  
  253. -> print the Text
  254.          SetDrMd(rport,RP_JAM1)
  255.           SetAPen(rport,1)
  256.            Move(rport,x+3, pos+self.max-((self.max-self.fh)/2)-2)
  257.             Text(rport,text,StrLen(text))
  258.         IF (image<>NIL) THEN DrawImage(rport,image,x+xs-image.width-3,((self.max-image.height)/2)+pos+2)
  259.  
  260.       ENDIF
  261.      ENDIF
  262.     actpos:=actpos+width
  263.     item++
  264.    ENDWHILE
  265. ENDPROC
  266.  
  267. PROC message_test(imsg:PTR TO intuimessage,w:PTR TO window)     OF register
  268.  DEF    item=0,
  269.         text=NIL,
  270.         width=0,
  271.         image=NIL:PTR TO image,
  272.         actpos=0,
  273.         height=0
  274.   IF (imsg.code=SELECTDOWN) AND (imsg.class=IDCMP_MOUSEBUTTONS)
  275.    IF (imsg.mousex>=self.x) AND (imsg.mousey>self.y) 
  276.     IF (imsg.mousey<(self.y+self.ys)) AND ((imsg.mousex<self.x+self.xs))
  277.      IF self.dir=REG_ABOVE
  278.       actpos:=self.x
  279.        WHILE (text:=ListItem(self.list,item*2))
  280.         image:=ListItem(self.list,(item*2)+1)
  281.          width:=textlen(text,self.gh.tattr)+8
  282.           width:=IF (self.xs>self.width) THEN width+((self.xs-self.width)/self.num) ELSE width
  283.            IF (image<>NIL) THEN width:=width+image.width+2
  284.           IF (imsg.mousex>=actpos) AND (imsg.mousex<=(actpos+width) )
  285.            IF (imsg.mousey>self.y) AND (imsg.mousey<(self.y+self.xs))
  286.             self.set(item)
  287.              RETURN TRUE
  288.            ENDIF
  289.           ENDIF
  290.          actpos:=actpos+width
  291.         item:=item+1
  292.        ENDWHILE
  293.      ELSE
  294.       WHILE (text:=ListItem(self.list,item*2))
  295.        image:=ListItem(self.list,(item*2)+1)
  296.         height:=self.max+4
  297.         actpos:=((item)*(height))+self.y+(((self.ys-self.height)/self.num)*item)
  298.         IF (imsg.mousey>=actpos) AND (imsg.mousey<=(actpos+self.max))
  299.          IF (imsg.mousex>self.x) AND (imsg.mousex<(self.x+self.xs))
  300.           self.set(item)
  301.            RETURN TRUE
  302.          ENDIF
  303.         ENDIF
  304.        item:=item+1
  305.       ENDWHILE
  306.      ENDIF
  307.     ENDIF
  308.    ENDIF
  309.   ENDIF
  310. ENDPROC FALSE
  311.  
  312. PROC clear_render(w:PTR TO window)                              OF register
  313.  DEF    rport=NIL
  314.   rport:=w.rport
  315.    SetAPen(rport,0)
  316.     SetBPen(rport,0)
  317.      RectFill(rport,self.x,self.y,self.x+self.xs,self.y+self.ys)
  318. ENDPROC
  319.  
  320. PROC set(num)                                                   OF register
  321.  IF (num>=0) AND (num<self.num) THEN self.active:=num ELSE RETURN FALSE
  322. ng_setattrsA([
  323.         NG_GUI,         self.gh,
  324.         NG_REDRAW,      self,
  325.         NIL,            NIL])
  326. ENDPROC TRUE
  327.  
  328. PROC get()                                                      OF register IS self.active
  329.